
//
//  SCSegmentScrollView.m
//  BOSS-SOOC
//
//  Created by apple on 16/8/26.
//  Copyright © 2016年 Gcx. All rights reserved.
//
#define MainScreen_W [UIScreen mainScreen].bounds.size.width

#import "SCSegmentScrollView.h"

#import "SCUIToolHeader.h"


@interface SCSegmentScrollView()<UIScrollViewDelegate>


@end

@implementation SCSegmentScrollView


-(instancetype)initWithFrame:(CGRect)frame
                  titleArray:(NSArray *)titleArray
            contentViewArray:(NSArray *)contentViewArray{
    if (self = [super initWithFrame:frame]) {
        
        [self addSubview:self.bgScrollView];
        
        self.autoresizesSubviews = NO;
        
        _segmentToolView=[[SCSegmentView alloc] initWithFrame:CGRectMake(0, 0, MainScreen_W, 44) titles:titleArray clickBlick:^void(NSInteger index) {
            NSLog(@"-----%ld",(long)index);
            [_bgScrollView setContentOffset:CGPointMake(MainScreen_W*(index-1), 0)];
        }];
        [self addSubview:_segmentToolView];
        
        
        for (int i=0;i<contentViewArray.count; i++ ) {
            
            UIView *contentView = (UIView *)contentViewArray[i];
//            contentView.frame=CGRectMake(MainScreen_W * i, _segmentToolView.bounds.size.height, MainScreen_W, _bgScrollView.frame.size.height-_segmentToolView.bounds.size.height);
            [_bgScrollView addSubview:contentView];
        }
        
        
    }
    
    return self;
}






-(UIScrollView *)bgScrollView{
    if (!_bgScrollView) {
        _bgScrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, _segmentToolView.frame.size.height+20, MainScreen_W, self.bounds.size.height-_segmentToolView.bounds.size.height)];
        _bgScrollView.contentSize=CGSizeMake(MainScreen_W*2, 0);
        _bgScrollView.backgroundColor= Color999999;
        _bgScrollView.showsVerticalScrollIndicator=NO;
        _bgScrollView.showsHorizontalScrollIndicator=NO;
        _bgScrollView.delegate=self;
        _bgScrollView.bounces=NO;
        _bgScrollView.pagingEnabled=YES;
        
    }
    return _bgScrollView;
}



-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView==_bgScrollView)
    {
        NSInteger p=_bgScrollView.contentOffset.x/MainScreen_W;
        _segmentToolView.defaultIndex=p+1;
        
    }
    
}

-(void)setTitleColor:(UIColor *)color State:(UIControlState )state{
    
    switch (state) {
        case UIControlStateNormal:{
            [_segmentToolView setTitleNomalColor:color];

            
        }break;
        case UIControlStateSelected:{
            [_segmentToolView setTitleSelectColor:color];
            
            
        }break;
            
        default:
            break;
    }     
    
}
-(void)setLine_size:(CGFloat)line_size{
    
    _segmentToolView.line_size = line_size;
    
    
    
}
-(void)setLine_color:(UIColor *)line_color{
    
    _segmentToolView.line_color = line_color;
    
    
}
-(void)setBackgroud_color:(UIColor *)backgroud_color{
    _segmentToolView.backgroud_color = backgroud_color;
    
}


@end
